package service

import (
	"context"
	"shop-demo/app/user/service/internal/biz"

	pb "shop-demo/api/user/v1"
)

func (s *UserService) CreateUser(ctx context.Context, req *pb.CreateUserReq) (*pb.CreateUserReply, error) {
	user, err := s.uc.CreateUser(ctx, &biz.User{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		return nil, err
	}
	return &pb.CreateUserReply{
		Id:       user.Id,
		Username: user.Username,
	}, nil
}
func (s *UserService) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserReply, error) {
	user, err := s.uc.GetUser(ctx, req.Id)
	if err != nil {
		return nil, err
	}
	return &pb.GetUserReply{
		Id:       user.Id,
		Username: user.Username,
	}, nil
}
func (s *UserService) VerifyPassword(ctx context.Context, req *pb.VerifyPasswordReq) (*pb.VerifyPasswordReply, error) {
	user, err := s.uc.VerifyPassword(ctx, &biz.User{
		Username: req.Username,
		Password: req.Password,
	})
	if err == nil {
		return &pb.VerifyPasswordReply{
			Ok: true,
			Id: user.Id,
		}, nil
	}
	return &pb.VerifyPasswordReply{
		Ok: false,
	}, nil
}
